Skip to content

feat: add 'kosli get api-key' command#992

Merged
mbevc1 merged 2 commits into
mainfrom
20260706_get_key
Jul 6, 2026
Merged

feat: add 'kosli get api-key' command#992
mbevc1 merged 2 commits into
mainfrom
20260706_get_key

Conversation

@mbevc1

@mbevc1 mbevc1 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Add a 'get api-key' subcommand that fetches a single API key's metadata via GET /api/v2/service-accounts/{org}/{name}/api-keys/{key_id}, completing CRUD support for service-account API keys alongside the existing create/list/rotate/delete commands.

The command takes a positional KEY-ID and a required --service-account flag (consistent with delete/rotate), supports table and json output, and only ever returns key metadata - the secret value is shown once at creation/rotation time.

Also creates a reusable function to calculate timestamps.

Closes #991

Add a 'get api-key' subcommand that fetches a single API key's metadata
via `GET /api/v2/service-accounts/{org}/{name}/api-keys/{key_id}`,
completing CRUD support for service-account API keys alongside the
existing create/list/rotate/delete commands.

The command takes a positional KEY-ID and a required `--service-account`
flag (consistent with delete/rotate), supports table and json output,
and only ever returns key metadata - the secret value is shown once at
creation/rotation time.

Closes #991
@mbevc1 mbevc1 added enhancement New feature or request tech-investment go Pull requests that update go code labels Jul 6, 2026
@claude

claude Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Claude finished @mbevc1's task in 1m 56s —— View job


Review: kosli get api-key

  • Gather context (diff, changed files)
  • Static analysis (go build, go vet)
  • Review code quality, edge cases, tests
  • Post review summary

Verdict: LGTM. This is a clean, well-scoped slice that completes CRUD for service-account API keys. It follows the established delete/rotate/list conventions faithfully and the latest commit already resolved the earlier DRY note by extracting apiKeyMetadataTimestamps.

Static analysis

Check Result
go build ./... ✅ pass
go vet ./cmd/kosli/... ✅ pass
go mod tidy not run (no go.mod/go.sum changes in this PR)
Unit/suite tests ⚠️ could not execute — go test was not in my allowed tools. Build+vet pass and the test code reads correctly; the suite tests need the local server per CLAUDE.md. Please confirm make test_integration_single TARGET=TestApiKeyCommandTestSuite is green locally/CI.

What's good

  • Consistent with existing patternsgetApiKeyOptions, PreRunE global-flag check, RequireFlags, url.JoinPath, and the FormattedPrint table/json map all mirror listApiKeys.go/delete/rotate exactly.
  • DRY refactor landedapiKeyMetadataTimestamps (apiKey.go:34) is now shared by both the get renderer (apiKey.go:117) and the list renderer (listApiKeys.go:103), so the two can't drift. This addresses the prior review comment.
  • Security-conscious — the metadata struct (apiKeyMetadata) has no Key field, and the long/short help explicitly state the secret is only shown at creation/rotation. Good.
  • Solid test coverage — arg-count validation (0/1/2 args), missing --service-account, ak alias + -s shorthand, table vs json output, N/A rendering for zero timestamps, and a 404-surfaced-as-error case (apiKey_test.go:507). Fixture-driven contract in testdata/service-account/ keeps response bodies in one place.
  • No alias collisionak is unique among get subcommands (get.go:21-34).

Minor / non-blocking observations

  • Shadowing url (getApiKey.go:65): url, err := url.JoinPath(...) shadows the imported url package. It's correct (RHS evaluates before assignment) and matches listApiKeys.go:67, so it's consistent — just noting it as a readability micro-nit shared with the existing code; no change needed.
  • printApiKeyMetadataAsTable assumes a single object. The get endpoint returns one object, so this is correct. If the API ever returned an array on this path the unmarshal would error out cleanly rather than misbehave — fine as-is.

Nothing here blocks merge. Nice, tidy addition. 👍
· 20260706_get_key

@mbevc1 mbevc1 changed the title feat: add 'kosli get api-key' command (#991) feat: add 'kosli get api-key' command Jul 6, 2026
Comment thread cmd/kosli/apiKey.go
@mbevc1
mbevc1 enabled auto-merge (squash) July 6, 2026 12:03
@mbevc1
mbevc1 merged commit 96d8694 into main Jul 6, 2026
20 checks passed
@mbevc1
mbevc1 deleted the 20260706_get_key branch July 6, 2026 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code tech-investment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add full support for managing API keys

2 participants